package com.ymatou.iapi.selleraccount.testcase;

import java.util.HashMap;
import java.util.Map;

import org.json.JSONObject;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.selleraccount.service.QuerySellerRoleListCall;
import com.ymatou.iapi.selleraccount.service.UpdateRoleCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.tag.P1;

/**
 * @serial 2016-12-28
 * @author chencan
 * 子账号角色修改
 */
public class Tc_UpdateRole {
	private static UpdateRoleCall updateRoleCall;
	
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("业务说明：子账号角色修改");
	}

	@Before
	public void caseUp() {
		updateRoleCall = new UpdateRoleCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(updateRoleCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_UpdateRole_001 (){
		Logger.start(true, "子账号角色修改");  
		try{
			int sellerid = 3383;
			int size = 1;
			int index = 1;
			
			Map<String,Object> map1 = new HashMap<String,Object>();
			map1.put("SellerId",sellerid);
			map1.put("PageSize",size);
			map1.put("PageIndex",index);
			
			JSONObject retBea = new QuerySellerRoleListCall().callAndGetReturnData(map1);
			JSONObject data = retBea.getJSONObject("Data").getJSONArray("SellerRoleDtos").getJSONObject(0);
			
			int roleid = data.getInt("Roleid");
			int sellerids = data.getInt("Sellerid");
			String rolename = data.getString("RoleName");
			
			Map<String,Object> map = new HashMap<String,Object>();
			map.put("SellerId",sellerids);
			map.put("Roleid",roleid);
			map.put("RoleName",rolename);
			
			JSONObject retBeas = updateRoleCall.callAndGetReturnData(map);
			JSONObject datas = retBeas.getJSONObject("Data");
			int code = retBeas.getInt("Code");
			Boolean success = datas.getBoolean("Success");
			String message = datas.getString("ErrorMessage");
			
			Logger.verifyEquals(200, code, "code返回结果");
			Logger.verifyEquals(true, success, "返回结果状态");
			Logger.verifyEquals("修改角色成功", message, "描述");

			
		}catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_UpdateRole_002 (){
		Logger.start(true, "子账号角色修改-- 角色ID不存在");
		try{
			
			int roleid = 0;
			
			Map<String,Object> map = new HashMap<String,Object>();
			map.put("Roleid",roleid);
			
			JSONObject retBeas = new UpdateRoleCall().callAndGetReturnData(map);
			int code = retBeas.getInt("Code");
			Boolean success = retBeas.getBoolean("Success");
			String message = retBeas.getString("ErrorMessage");
			
			Logger.verifyEquals(500, code, "code返回结果");
			Logger.verifyEquals(false, success, "返回结果状态");
			Logger.verifyEquals("参数有误", message, "描述");

			
		}catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_UpdateRole_003 (){
		Logger.start(true, "子账号角色修改-- 主账号ID不存在");
		try{
			
			int sellerids = 0;
			
			Map<String,Object> map = new HashMap<String,Object>();
			map.put("SellerId",sellerids);
			
			JSONObject retBeas = new UpdateRoleCall().callAndGetReturnData(map);
			int code = retBeas.getInt("Code");
			Boolean success = retBeas.getBoolean("Success");
			String message = retBeas.getString("ErrorMessage");
			
			Logger.verifyEquals(500, code, "code返回结果");
			Logger.verifyEquals(false, success, "返回结果状态");
			Logger.verifyEquals("参数有误", message, "描述");

			
		}catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_UpdateRole_004 (){
		Logger.start(true, "子账号角色修改-- 角色不存在");
		try{
			
			String menuidList = "0";
			
			Map<String,Object> map = new HashMap<String,Object>();
			map.put("MenuidList",menuidList);
			
			JSONObject retBeas = new UpdateRoleCall().callAndGetReturnData(map);
			JSONObject datas = retBeas.getJSONObject("Data");
			int code = retBeas.getInt("Code");
			Boolean success = datas.getBoolean("Success");
			String message = datas.getString("ErrorMessage");
			
			Logger.verifyEquals(200, code, "code返回结果");
			Logger.verifyEquals(false, success, "返回结果状态");
			Logger.verifyEquals("修改角色失败", message, "描述");

			
		}catch (Exception e) {
			e.printStackTrace();
		}
	}
	

}
